home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-20 | 3.0 KB | 145 lines | [TEXT/CWIE] |
- // SVAEWindowUtils.c
- //
- // 7Edit 3.1d1. Original version by Jon Lansdell and Nigel Humphreys.
- // 3.1 updates by Greg Sutton.
- // ©Apple Computer Inc 1995, all rights reserved.
-
- #include "SVAEWindowUtils.h"
-
- #include "SVEditWindow.h" // for DPtrFromWindowPtr()
-
-
-
- #include <LowMem.h>
-
-
-
-
- WindowPtr WindowNameToWindowPtr(StringPtr nameStr)
- /*
- Returns the WindowPtr of the window with title nameStr
- or nil if there is no matching window.
- */
- {
- WindowPtr theWindow;
- Str255 windTitle;
-
- theWindow =(WindowPtr)LMGetWindowList();
- /*
- iterate through windows - we use WindowList 'cos we could
- have made the window invisible and we lose it - so we
- can't set it back to visible!!
- */
- while (theWindow)
- {
- GetWTitle(theWindow, windTitle);
- if (EqualString(windTitle,
- nameStr,
- false,
- true)) /* ignore case, don't ignore diacriticals */
- return(theWindow);
- theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
- }
- return(theWindow);
- } /* WindowNameToWindowPtr */
-
-
- OSErr GetDescOfNamedWindow(StringPtr nameStr, AEDesc* result)
- {
- WindowToken theToken;
- OSErr err = noErr;
-
- theToken.tokenWindow = WindowNameToWindowPtr(nameStr);
-
- if (theToken.tokenWindow)
- err = AECreateDesc(typeMyWndw, (Ptr)&theToken, sizeof(theToken), result);
- else
- err = errAENoSuchObject;
-
- return(err);
- }
-
-
- short CountWindows(void)
- {
- WindowPtr theWindow;
- short index;
-
- index = 0;
- theWindow = (WindowPtr)LMGetWindowList();
-
- // iterate through windows
- while (theWindow)
- {
- index++;
- theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
- }
-
- return(index);
- } // CountWindows
-
-
- WindowPtr GetWindowPtrOfNthWindow(short index)
- /* returns a ptr to the window with the given index
- (front window is 1, behind that is 2, etc.). if
- there's no window with that index (inc. no windows
- at all), returns nil.
- */
- {
- WindowPtr theWindow;
-
- theWindow = (WindowPtr)LMGetWindowList();
-
- /* iterate through windows */
-
- while (theWindow)
- {
- index --;
- if (index <= 0)
- return(theWindow);
-
- theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
- }
- return(nil);
- } /* GetWindowPtrOfNthWindow */
-
- short GetNthWindowOfWindowPtr(WindowPtr aWindow)
- // Given a WindowPtr this routine tries to find the
- // index to that window. If not found it will return
- // zero
- {
- WindowPtr theWindow;
- short index;
-
- index = 0;
- theWindow = (WindowPtr)LMGetWindowList();
-
- // iterate through windows
- while (theWindow)
- {
- index++;
- if (theWindow == aWindow)
- return(index);
-
- theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
- }
-
- return(0);
- } // GetNthWindowOfWindowPtr
-
-
- OSErr GetDescOfNthWindow(short index, AEDesc* result)
- {
- WindowToken theToken;
- OSErr err = noErr;
-
- theToken.tokenWindow = GetWindowPtrOfNthWindow(index);
-
- if (theToken.tokenWindow)
- err = AECreateDesc(typeMyWndw, (Ptr)&theToken, sizeof(theToken), result);
- else
- err = errAEIllegalIndex;
-
- return(err);
- }
-